package com.hundredapp.oa.repository;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hundredapp.oa.dao.GenericDao;
import com.hundredapp.oa.domain.OaAction;
import com.hundredapp.oa.domain.OaWorktime;

@Repository
public class WorktimeManagerImpl implements WorktimeManager {

	@Autowired
	private GenericDao<OaAction, Integer> actionDao;
	@Autowired
	private GenericDao<OaWorktime, Integer> worktimeDao;
	
	@Override
	public int add(OaWorktime worktime) {
		return worktimeDao.save(worktime);
	}

	@Override
	public List<OaWorktime> findWorktimes(String condition, int start,
			int limit) {
		return worktimeDao.find(condition, start, limit);
	}

	@Override
	public OaWorktime findWorktime(String condition) {
		return worktimeDao.findUnique(condition);
	}

	@Override
	public OaWorktime findWorktimeById(int id) {
		return worktimeDao.findById(id);
	}

	@Override
	public void delete(int id) {
		worktimeDao.remove(worktimeDao.findById(id));
	}

	@Override
	public void update(OaWorktime worktime) {
		worktimeDao.modify(worktime);
	}

	@Override
	public int count(String condition) {
		return worktimeDao.count(condition);
	}

	@Override
	public void deletebyclass(int classid) {
		for(OaWorktime wt:worktimeDao.find(" oaClass.id = "+classid)){
			worktimeDao.remove(wt);
		}
	}

}
